package com.hopes.bizz.risk.tenant.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hopes.bizz.risk.integral.entity.RiskIntegralEventEntity;
import com.hopes.bizz.risk.integral.service.RiskIntegralEventService;
import com.hopes.bizz.risk.tenant.service.TenantConfigInitService;
import com.hopes.boss.admin.api.entity.SysTenant;
import com.hopes.boss.common.data.tenant.TenantContextHolder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yumr
 * @ProjectName bizz
 * @Description 积分事件租户初始化
 * @time 2023/8/16 18:13
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RiskIntegralEventTenantInitServiceImpl implements TenantConfigInitService {


    private final RiskIntegralEventService riskIntegralEventService;

    @Override
    public String getName() {
        return "初始化积分事件";
    }

    @Override
    public void init(SysTenant tenant) {
        final Long tenantId = tenant.getId();

        final List<RiskIntegralEventEntity> list = riskIntegralEventService.list(
                Wrappers.<RiskIntegralEventEntity>lambdaQuery().eq(RiskIntegralEventEntity::getTenantId, TenantContextHolder.getAdminTenantId()));
        for (RiskIntegralEventEntity entity : list) {
            entity.setId(null);
            entity.setTenantId(tenantId);
        }
        riskIntegralEventService.saveBatch(list);
    }
}
